﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MadProps.TypeDescription
{
    class PropDescriptor : BasePropertyDescriptor
    {
        readonly IProp prop;

        public PropDescriptor(IProp prop)
            : base(Meta.PropertyName.Of(prop), prop.PropId.ClrMember.GetCustomAttributes(false).ToArray())
        {
            this.prop = prop.ThrowIfNull("prop");
        }

        public override Type ComponentType
        {
            get { return prop.Owner.GetType(); }
        }

        public override object GetValue(object component)
        {
            return prop.Value;
        }

        public override bool IsReadOnly
        {
            get { return Meta.IsReadOnly.Of(prop); }
        }

        public override Type PropertyType
        {
            get { return prop.Type; }
        }

        public override void SetValue(object component, object value)
        {
            prop.Value = value;
        }
    }
}
